﻿namespace Utility3D
{
    public struct Vector3D
    {
        private System.Windows.Media.Media3D.Vector3D _vector;

        public Vector3D(double x, double y, double z)
        {
            _vector = new System.Windows.Media.Media3D.Vector3D(x, y, z);
        }

        private Vector3D(System.Windows.Media.Media3D.Vector3D vector)
        {
            _vector = vector;
        }

        public double X { get { return _vector.X; } set { _vector.X = value; } }
        public double Y { get { return _vector.Y; } set { _vector.Y = value; } }
        public double Z { get { return _vector.Z; } set { _vector.Z = value; } }

        public double Length { get { return _vector.Length; } }

        public Vector3D Unit()
        {
            var unitVector = new System.Windows.Media.Media3D.Vector3D(X, Y, Z);
            unitVector.Normalize();
            return new Vector3D(unitVector);
        }

        public static Vector3D operator *(Vector3D vector3D, double length)
        {
            return new Vector3D(vector3D._vector*length);
        }

        public static Point3D operator +(Point3D point3D, Vector3D vector3D)
        {
            var vectorPoint = new System.Windows.Media.Media3D.Point3D(point3D.X, point3D.Y, point3D.Z);
            var newPoint = vectorPoint + vector3D._vector;
            return new Point3D(newPoint.X, newPoint.Y, newPoint.Z);
        }

        public double DotProduct(Vector3D normal)
        {
            return System.Windows.Media.Media3D.Vector3D.DotProduct(_vector, normal._vector);
        }

        public Vector3D CrossProduct(Vector3D vector)
        {
            return new Vector3D(System.Windows.Media.Media3D.Vector3D.CrossProduct(_vector, vector._vector));
        }

        public static bool operator==(Vector3D vector1, Vector3D vector2)
        {
            return vector1.X == vector2.X
                   && vector1.Y == vector2.Y
                   && vector1.Z == vector2.Z;
        }

        public static bool operator !=(Vector3D vector1, Vector3D vector2)
        {
            return !(vector1 == vector2);
        }
    }
}